package com.ruoyi.equipment.api.service;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.equipment.domain.LgEquipmentError;
import com.ruoyi.equipment.domain.LgMachine;
import com.ruoyi.equipment.domain.LgTemperature;
import com.ruoyi.equipment.domain.LgVehicle;
import com.ruoyi.equipment.mapper.LgEquipmentErrorMapper;
import com.ruoyi.equipment.mapper.LgTemperatureMapper;
import com.ruoyi.equipment.service.LgMachineService;
import com.ruoyi.equipment.service.LgTemperatureService;
import com.ruoyi.equipment.service.impl.LgEquipmentErrorServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: lek
 * @Description: TODO
 * @Date: 2025/3/10 18:20
 * @Version: 1.0
 */
@RestController
@RequestMapping("/api")
public class Lll{
    @Autowired
    private LgTemperatureMapper lgTemperatureMapper;
    @Autowired
    private LgTemperatureService lgTemperatureService;
    @Autowired
    private LgEquipmentErrorServiceImpl lgEquipmentErrorService;
    @Autowired
    private LgEquipmentErrorMapper lgEquipmentErrorMapper;
    @Autowired
    private LgMachineService lgMachineService;
    @GetMapping("/list")
    public List<LgTemperature> list1(){
        return lgTemperatureMapper.selectList(null);
    }

    @PostMapping("/setTem")
    public int setTem(@RequestBody LgTemperature lgTemperature){

        return lgTemperatureMapper.updateById(lgTemperature);
    }

    @PostMapping("/select")
    public List<LgVehicle> selectLgVehicleList(@RequestBody LgVehicle lgVehicle){
        List<LgVehicle> list = lgTemperatureMapper.selectLgVehicleList(lgVehicle);
        return list;
    }

    @PostMapping("/selectByVehicleId")
    public LgTemperature selectLgVehicleById(@RequestParam("id") Integer id){
        LgTemperature lgTemperature = lgTemperatureMapper.selectTemperatureVehicleById(id);
        if (lgTemperature == null){
            return null;
        }
        return lgTemperature;
    }

    @PostMapping("/selectBylicensePlate")
    public LgTemperature selectLgVehicleBylicensePlate(@RequestParam("licensePlate") String licensePlate){
        LgTemperature lgTemperature = lgTemperatureMapper.selectTemperatureVehicleBylicensePlate(licensePlate);
        if (lgTemperature == null){
            return null;
        }
        return lgTemperature;
    }

    @PostMapping("/update")
    public int edit(@RequestBody LgEquipmentError lgEquipmentError)
    {
        return lgEquipmentErrorService.updateLgEquipmentError(lgEquipmentError);
    }

    @PostMapping("/listee")
    public List<LgEquipmentError> list(@RequestBody LgEquipmentError lgEquipmentError)
    {
        return lgEquipmentErrorService.selectLgEquipmentErrorList(lgEquipmentError);
    }

    @PostMapping("/insertorderlocation")
    public AjaxResult insertOrderLocation(){
        return AjaxResult.success( lgTemperatureService.insertOrderLocation());
    }

    @GetMapping("/count")
    public AjaxResult count(){
        return AjaxResult.success(lgEquipmentErrorMapper.selectLgEquipmentErrorCountList());
    }

    @PostMapping("/listmac")
    public List<LgMachine> list(LgMachine lgMachine){
        List<LgMachine> list = lgMachineService.selectLgMachineList(lgMachine);
        return list;
    }
    @PostMapping("/selectByMacId")
    public LgMachine getInfo(@RequestParam("id") String id){
        LgMachine lgMachine = lgMachineService.selectLgMachineById(Integer.valueOf(id));
        return lgMachine;
    }
    @PostMapping("/updatemac")
    public int update(@RequestBody LgMachine lgMachine){
        int i = lgMachineService.updateLgMachine(lgMachine);
        return i;
    }
    @PostMapping("/getTemInfo")
    public LgTemperature getTemInfo(@RequestParam("id")Integer id){
        LgTemperature lgTemperature = lgTemperatureService.selectLgTemperatureById(id);
        return lgTemperature;
    }

    @PostMapping("/getEquipError")
    public LgEquipmentError getEquipError(@RequestParam("deviceNumber")Integer deviceNumber){
        LgEquipmentError lgEquipmentError = lgEquipmentErrorMapper.selectLgEquipmentErrorByDeviceNumber(deviceNumber);
        return lgEquipmentError;
    }

    @PostMapping("/insertEquipError")
    public int insertEquipError(@RequestBody LgEquipmentError lgEquipmentError){
        int i = lgEquipmentErrorService.insertLgEquipmentError(lgEquipmentError);
        return i;
    }
}
